﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="..\Resources\Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="18"/>
            </Grid.ColumnDefinitions>
            <Border
                x:Name="Border" 
                Grid.ColumnSpan="2"
                CornerRadius="2"
                Background="{StaticResource NormalBrush}"
                BorderBrush="{StaticResource NormalBorderBrush}"
                BorderThickness="1"/>
            <Border 
                Grid.Column="0"
                CornerRadius="2,0,0,2" 
                Margin="1" 
                Background="{StaticResource WindowBackgroundBrush}" 
                BorderBrush="{StaticResource NormalBorderBrush}"
                BorderThickness="0,0,1,0" />
            <Path 
                x:Name="Arrow"
                Grid.Column="1"     
                Fill="{StaticResource GlyphBrush}"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Data="M -2 1 L 2 6 L 6 1 Z"/>
        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="ToggleButton.IsMouseOver" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DarkBrush}" />
            </Trigger>
            <Trigger Property="ToggleButton.IsChecked" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <ControlTemplate x:Key="ComboBoxTextBox" TargetType="TextBox">
        
        <Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" Width="{TemplateBinding Width}"/>
        
    </ControlTemplate>

    <ControlTemplate TargetType="ComboBox" x:Key="ComboBoxTemplate">
        <Grid>

            <ToggleButton 
                Name="ToggleButton" 
                Template="{StaticResource ComboBoxToggleButton}" 
                Grid.Column="2" 
                Focusable="false"
                IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                ClickMode="Press">
            </ToggleButton>

            <ContentPresenter
                Name="ContentSite"
                IsHitTestVisible="False" 
                Content="{TemplateBinding SelectionBoxItem}"
                ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                Margin="3,3,23,3"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />
            <TextBox
                Name="PART_EditableTextBox"
                Style="{x:Null}" 
                Template="{StaticResource ComboBoxTextBox}" 
                HorizontalAlignment="Stretch" 
                VerticalAlignment="Center" 
                Margin="3,3,23,3"
                Focusable="True" 
                Background="Transparent"
                Visibility="Hidden"
                IsReadOnly="{TemplateBinding IsReadOnly}"/>
            <Popup
                Name="Popup" AllowDrop="True"
                Placement="Bottom"
                IsOpen="{TemplateBinding IsDropDownOpen}"
                AllowsTransparency="True" 
                Focusable="False"
                PopupAnimation="Slide">
                <Grid 
                    Name="DropDown"
                    SnapsToDevicePixels="True"                                                 
                    MinWidth="{TemplateBinding ActualWidth}"
                    MaxHeight="{Binding Height, ElementName=DropDownBorder}">
                    <Border 
                        x:Name="DropDownBorder"
                        Background="{StaticResource WindowBackgroundBrush}"
                        BorderBrush="{StaticResource SolidBorderBrush}"
                        BorderThickness="1">
                        <StackPanel>
                            <ScrollViewer MaxHeight="{TemplateBinding MaxDropDownHeight}" Margin="2" SnapsToDevicePixels="True">
                                <VirtualizingStackPanel IsItemsHost="True" IsVirtualizing="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                            </ScrollViewer>
                        </StackPanel>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="HasItems" Value="false">
                <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
            </Trigger>
            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
                <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
            </Trigger>
            <Trigger Property="IsEditable"  Value="true">
                <Setter Property="IsTabStop" Value="false"/>
                <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
                <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate TargetType="ComboBox" x:Key="SearchComboBoxTemplate">
        <Grid>

            <ToggleButton 
                Name="ToggleButton" 
                Template="{StaticResource ComboBoxToggleButton}" 
                Grid.Column="2" 
                Focusable="false"
                IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                ClickMode="Press">
            </ToggleButton>

            <ContentPresenter
                Name="ContentSite"
                IsHitTestVisible="False" 
                Content="{TemplateBinding SelectionBoxItem}"
                ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                Margin="3,3,23,3"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />
            <TextBox 
                Name="PART_EditableTextBox"
                Style="{x:Null}" 
                Template="{StaticResource ComboBoxTextBox}" 
                Text="{TemplateBinding Text}"
                HorizontalAlignment="Left" 
                VerticalAlignment="Center" 
                Margin="3,3,23,3"
                Focusable="True" 
                Background="Transparent"
                Visibility="Hidden"
                IsReadOnly="{TemplateBinding IsReadOnly}"/>               
            <Popup
                Name="Popup"
                AllowDrop="True"
                Placement="Bottom"
                IsOpen="{TemplateBinding IsDropDownOpen}"
                AllowsTransparency="True" 
                Focusable="False"
                PopupAnimation="Slide">
                <Grid 
                    Name="DropDown"
                    SnapsToDevicePixels="True"                                                 
                    MinWidth="{TemplateBinding ActualWidth}"
                    MaxHeight="{Binding Height, ElementName=DropDownBorder}">
                    <Border 
                        x:Name="DropDownBorder"
                        Background="{StaticResource WindowBackgroundBrush}"
                        BorderBrush="{StaticResource SolidBorderBrush}"
                        BorderThickness="1">
                        <StackPanel>
                            <Border CornerRadius="2,2,0,0" Background="{StaticResource NormalBorderBrush}">
                                <StackPanel Orientation="Horizontal" Width="Auto">
                                    <StackPanel.Resources>
                                        <Style TargetType="TextBlock">
                                            <Setter Property="Margin" Value="0"/>
                                        </Style>
                                    </StackPanel.Resources>
                                    <Button Command="{Binding CheckAll}" Content="{Localizing CheckAll}" Width="88" Margin="4" Padding="8 1 8 1"/>
                                    <Button Command="{Binding UncheckAll}" Content="{Localizing UncheckAll}" Width="88" Margin="4" Padding="8 1 8 1" HorizontalAlignment="Right"/>
                                </StackPanel>
                            </Border>
                            <ScrollViewer Margin="2" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True">
                                <VirtualizingStackPanel Name="ItemsPanel" IsItemsHost="True" IsVirtualizing="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                            </ScrollViewer>
                        </StackPanel>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="HasItems" Value="false">
                <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
                <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
            </Trigger>
            <Trigger Property="IsEditable"  Value="true">
                <Setter Property="IsTabStop" Value="false"/>
                <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
                <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

	<ControlTemplate TargetType="ComboBox" x:Key="BrushComboBoxTemplate">
		<Grid>

			<ToggleButton 
                Name="ToggleButton" 
                Template="{StaticResource ComboBoxToggleButton}" 
                Grid.Column="2" 
                Focusable="false"
                IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                ClickMode="Press">
			</ToggleButton>

			<ContentPresenter
                Name="ContentSite"
                IsHitTestVisible="False" 
                Content="{TemplateBinding SelectionBoxItem}"
                ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                Margin="3,3,23,3"
                VerticalAlignment="Center"
                HorizontalAlignment="Left" />
			<TextBox 
                Name="PART_EditableTextBox"
                Style="{x:Null}" 
                Template="{StaticResource ComboBoxTextBox}" 
                Text="{TemplateBinding Text}"
                HorizontalAlignment="Left" 
                VerticalAlignment="Center" 
                Margin="3,3,23,3"
                Focusable="True" 
                Background="Transparent"
                Visibility="Hidden"
                IsReadOnly="{TemplateBinding IsReadOnly}"/>
			<Popup
                Name="Popup"
                AllowDrop="True"
                Placement="Bottom"
                IsOpen="{TemplateBinding IsDropDownOpen}"
                AllowsTransparency="True" 
                Focusable="False"
                PopupAnimation="Slide">
				<Grid 
                    Name="DropDown"
                    SnapsToDevicePixels="True"                                                 
                    MinWidth="{TemplateBinding ActualWidth}"
                    MaxHeight="{Binding Height, ElementName=DropDownBorder}">
					<Border 
                        x:Name="DropDownBorder"
                        Background="{StaticResource WindowBackgroundBrush}"
                        BorderBrush="{StaticResource SolidBorderBrush}"
                        BorderThickness="1">
						<StackPanel>
							<Border CornerRadius="2,2,0,0" Background="{StaticResource NormalBorderBrush}">
								<StackPanel Orientation="Horizontal" Width="Auto" DataContext="{TemplateBinding SelectedValue}">
									<StackPanel.Resources>
										<Style TargetType="TextBlock">
											<Setter Property="Margin" Value="0"/>
										</Style>
									</StackPanel.Resources>
									<TextBlock Text="{Localizing Opacity}"/>
									<ScrollBar Width="100" Orientation="Horizontal" Minimum="0" Maximum="1" SmallChange="0.1" Value="{Binding Opacity, Mode=OneWayToSource, FallbackValue=0.5, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}"/>
								</StackPanel>
							</Border>
							<ScrollViewer Margin="2" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True">
								<VirtualizingStackPanel Name="ItemsPanel" IsItemsHost="True" IsVirtualizing="True" KeyboardNavigation.DirectionalNavigation="Contained" />
							</ScrollViewer>
						</StackPanel>
					</Border>
				</Grid>
			</Popup>
		</Grid>
		<ControlTemplate.Triggers>
			<Trigger Property="HasItems" Value="false">
				<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="false">
				<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
			</Trigger>
			<Trigger Property="IsGrouping" Value="true">
				<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
			</Trigger>
			<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
				<Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
				<Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
			</Trigger>
			<Trigger Property="IsEditable"  Value="true">
				<Setter Property="IsTabStop" Value="false"/>
				<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
				<Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
	
	<ControlTemplate TargetType="ComboBoxItem" x:Key="ComboBoxItemTemplate">
        <Border 
            CornerRadius="2"
            BorderThickness="0"
            Name="Border"
            Padding="4,2"
            SnapsToDevicePixels="true">
            <ContentPresenter/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <ControlTemplate TargetType="ComboBoxItem" x:Key="SearchComboBoxItemTemplate">
        <Border 
            CornerRadius="2"
            BorderThickness="0"
            Name="Border"
            Padding="0"
            SnapsToDevicePixels="true">
            <ContentPresenter/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate TargetType="CheckBox" x:Key="CheckBoxTemplate">
        <BulletDecorator Background="Transparent">
            <BulletDecorator.Bullet>
                <Border x:Name="Border"  
                Width="13" 
                Height="13" 
                CornerRadius="2" 
                Background="{StaticResource NormalBrush}"
                BorderThickness="1"
                BorderBrush="{StaticResource NormalBorderBrush}">
                    <Path 
                  Width="7" Height="7" 
                  x:Name="CheckMark"
                  SnapsToDevicePixels="False" 
                  Stroke="{StaticResource GlyphBrush}"
                  StrokeThickness="2"
                  Data="M 0 0 L 7 7 M 0 7 L 7 0" />
                </Border>
            </BulletDecorator.Bullet>
            <ContentPresenter Margin="4,0,0,0"
              VerticalAlignment="Center"
              HorizontalAlignment="Left"
              RecognizesAccessKey="True"/>
        </BulletDecorator>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="false">
                <Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="{x:Null}">
                <Setter TargetName="CheckMark" Property="Data" Value="M 0 7 L 7 0" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DarkBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate TargetType="Button" x:Key="ButtonTemplate">
        <Border 
            x:Name="Border"  
            CornerRadius="2" 
            BorderThickness="1"
            Background="{StaticResource NormalBrush}"
            BorderBrush="{StaticResource NormalBorderBrush}">
            <ContentPresenter 
              Margin="2"
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              RecognizesAccessKey="True"/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsKeyboardFocused" Value="true">
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" />
            </Trigger>
            <Trigger Property="IsDefaulted" Value="true">
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DarkBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
            </Trigger>
            <!--<SnippetIsEnabledTrigger>-->
            <Trigger Property="IsEnabled" Value="false">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
            <!--</SnippetIsEnabledTrigger>-->
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate TargetType="{x:Type TextBoxBase}" x:Key="TextBoxTemplate">
        <Border 
            Name="Border"
            CornerRadius="2" 
            Padding="2"
            Background="{StaticResource WindowBackgroundBrush}"
            BorderBrush="{StaticResource SolidBorderBrush}"
            BorderThickness="1" >
            <ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/>
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBackgroundBrush}"/>
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

</ResourceDictionary>